# 作者：小七
# 2024年12月31日

class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name}占地{self.area}平方米"


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.items_list = []

    def __str__(self):
        return f"户型：{self.house_type}\n总面积：{self.area}[剩余面积：{self.free_area}]\n家具列表：{self.items_list}"

    def add_item(self, item: HouseItem):
        if item.area > self.free_area:
            print(f"{item.name}的面积太大，无法添加")
            return
        else:
            self.items_list.append(item.name)
            self.free_area -= item.area
            print(f"{item.name}添加成功")


if __name__ == '__main__':
    bed = HouseItem("席梦思", 4)
    table = HouseItem("沙发", 6)
    chair = HouseItem("椅子", 2)
    print(bed)
    print(table)
    print(chair)
    house = House("两室一厅", 30)
    house.add_item(bed)
    house.add_item(table)
    house.add_item(chair)
    print(house)